<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>出行规划</title>
    <link rel="stylesheet" type="text/css" href="css/weui/base.css"/>
    <style type="text/css">
        .MaxDIV {
            margin-top: 0.71em;
            margin-bottom: 0.71em;
        }

        .div-left {
            height: 660px;
            border: 1px solid #ccc;
        }

        .div-left .div-left-top {
            width: 100%;
            height: 40px;
            background-color: #0070b4;
            padding: 6px;
        }

        .div-left .div-left-top ul li {
            float: left;
            text-align: center;
            width: 33.3%;
            height: 28px;
            line-height: 2;
            cursor: pointer;
            color: white;
        }

        .div-left .public_div {
            position: relative;
            width: 100%;
            padding: 10px;
        }

        .div-left .public_div label {
            display: inline-block;
            width: 24%;
            height: 30px;
            vertical-align: middle;
        }

        .div-left .public_div input {
            width: 60%;
            height: 30px;
            -webkit-border-radius: 5px;
            -moz-border-radius: 5px;
            border-radius: 5px;
        }

        #DEST_collect {
            display: block;
            width: 21px;
            height: 21px;
            position: absolute;
            right: 20px;
            top: 14px;
            background: url("../../images/Icon_sc_03.png") no-repeat;
        }

        #transfer {
            border-bottom: 1px dashed #ccc;
        }

        .div-left .ghfs_div {
            border-top: 1px dashed #ccc;
            margin-top: 16px;
            height: 30px;
            width: 100%;
            background-color: #ccc;

        }

        .div-left .ghfs_div ul {
            width: 100%;
            height: 30px;
            padding: 0 5px;
        }

        .public_ghfs ul li {
            float: left;
            text-align: center;
            width: 33.3%;
            height: 28px;
            line-height: 2;
            cursor: pointer;
        }

        .action_o {
            background-color: #0070b4;
            color: white;
        }

        .div-left .result {
            margin-top: 6px;
            height: 408px;
            overflow: auto;
        }

        .action {
            background-color: #e9ab00;
        }

        .div-right {
            height: 660px;
            position: relative;
        }

        .div-right #l-map {
            width: 100%;
            height: 100%;
            -webkit-border-radius: 5px;
            -moz-border-radius: 5px;
            border-radius: 5px;
        }

        #choose {
            display: none;
            position: absolute;
            top: 20px;
            right: 20px;
            padding: 10px;
            background-color: #fff;
            z-index: 11;
            -webkit-box-shadow: 2px 3px 4px #CCC;
            -moz-box-shadow: 2px 3px 4px #CCC;
            box-shadow: 2px 3px 4px #CCC;
        }

        #choose input {
            margin-right: 5px;
        }
        #choose span {
            padding-left: 24px;
        }
        #choose span:nth-of-type(1){
            background: url("../../images/shoufeizhan.png") no-repeat left;
        }
        #choose span:nth-of-type(2){
            background: url("../../images/fuwuqu.png") no-repeat left;
        }
        #choose span:nth-of-type(3){
            background: url("../../images/lvyou.png") no-repeat left;
        }
        /*景点信息标题居中*/
        .div-right .BMap_bubble_title {
            text-align: center;
            font-weight: 700;
        }
        /*提示框*/
        #tishiInfo {
            padding: 20px 30px;
            text-align: center;
            background-color: #0070b4;
            color: white;
            font-size: 1.2em;
            position: fixed;
            left: 50%;
            top: 10%;
            -webkit-transform: translate(-50%);
            -moz-transform: translate(-50%);
            -ms-transform: translate(-50%);
            -o-transform: translate(-50%);
            transform: translate(-50%);
            display: none;
        }
    </style>
</head>

<body>
<div class="MaxDIV w">
    <!--<div class="Yourlocation">-->
    <!--<a href="#首页">首页</a>>-->
    <!--&lt;!&ndash;<a href="#专项查询">专项查询</a>>&ndash;&gt;-->
    <!--<a href="#公交查询">出行规划</a>-->
    <!--</div>-->
    <div class="div-left">
        <div class="div-left-top">
            <ul>
                <li class="action">
                    驾车规划
                </li>
                <li>
                    公交规划
                </li>
                <li>
                    步行规划
                </li>
            </ul>
        </div>
        <div id="transfer">
            <div class="public_div">
                <label for="start">出发地点: </label><input id="start" type="text">
            </div>
            <div class="public_div">
                <label for="end">目的地点: <a href="javascript:void(0);" title="收藏按钮" id="DEST_collect"></a></label><input
                    id="end" type="text">
            </div>
            <div id="searchResultPanel" style="border:1px solid #C0C0C0;width:150px;height:auto; display:none;"></div>
            <div id="driving_but_div" style="text-align: center;margin: 8px 0 16px;">
                <a id="driving_but" href="javascript:;" class="myButton">查&nbsp;询</a>
            </div>
            <div id="transfer_but_div" style="text-align: center;margin: 8px 0 16px;display: none;">
                <a id="transfer_but" href="javascript:;" class="myButton">查&nbsp;询</a>
            </div>
            <div id="walking_but_div" style="text-align: center;margin: 8px 0 16px;display: none;">
                <a id="walking_but" href="javascript:;" class="myButton">查&nbsp;询</a>
            </div>
        </div>
        <div class="ghfs_div">
            <div class="public_ghfs" id="driving_div">
                <!--<p>规划方式: </p>-->
                <!--<select id="mode_driving" class="select">-->
                <!--<option value="0" selected="selected">最少时间</option>-->
                <!--<option value="1">最短距离</option>-->
                <!--<option value="2">避开高速</option>-->
                <!--</select>-->
                <ul>
                    <li class="action_o">避免拥堵</li>
                    <li>最短距离</li>
                    <li>避开高速</li>
                </ul>
            </div>
            <div class="public_ghfs" id="transit_div" style="display: none;">
                <div>
                    <ul>
                        <li class="action_o">最少时间</li>
                        <li>最少换乘</li>
                        <li>不乘地铁</li>
                    </ul>
                </div>
            </div>
            <div id="kb_div" style="width:100%;height: 55px;display: none;"></div>
        </div>
        <div id="r-result" class="result">

        </div>
    </div>
    <div class="div-right">
        <div id="l-map">
        </div>
        <div id="choose">
            <input type="checkbox" name="choose-box" 　value="0"/><span>收费站</span>
            <br/>
            <br/>
            <input type="checkbox" name="choose-box" value="1"/><span>服务区</span>
            <br/>
            <br/>
            <input type="checkbox" name="choose-box" value="2"/><span>附近景点</span>
        </div>
    </div>
    <div style="clear: both"></div>
    <!--<div>-->
    <!--<input id="my_btn" type="button"/>-->
    <!--</div>-->
    <!--提示-->
    <div>
        <p id="tishiInfo"></p>
    </div>
</div>
<script src="js/jquery-1.11.0.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="https://api.map.baidu.com/api?v=2.0&ak=MMh4H9m5FLBpizlht86GnGynuaM0oGKz"></script>
<script src="js/back_end.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
    var map = new BMap.Map("l-map");
    map.centerAndZoom("吉林省", 9);
    map.enableScrollWheelZoom(true);

    $(".div-left-top ul li").each(function (i) {
        $(this).click(function () {
            $(this).addClass("action").siblings("li").removeClass("action");
            $("#r-result").html("");
            map.clearOverlays();
            if (i == 0) {
                $("#driving_div").show();
                $("#transit_div").hide();
                $("#kb_div").hide();
                $("#driving_but_div").show();
                $("#transfer_but_div").hide();
                $("#walking_but_div").hide();
            } else if (i == 1) {
                $("#driving_div").hide();
                $("#kb_div").hide();
                $("#transit_div").show();
                $("#transfer_but_div").show();
                $("#driving_but_div").hide();
                $("#walking_but_div").hide();
            } else if (i == 2) {
                $("#transit_div").hide();
                $("#driving_div").hide();
                $("#transfer_but_div").hide();
                $("#driving_but_div").hide();
                $("#walking_but_div").show();
                $("#kb_div").show();
            }
        });
    });
    $("#driving_div ul li ").each(function () {
        $(this).click(function () {
            var i = $(this).index();
            var a;
            $(this).addClass("action_o").siblings("li").removeClass("action_o");
            $("#r-result").html("");
            map.clearOverlays();
            if (i == 0) {
                a = 13;
            } else if (i == 1) {
                a = 12;
            } else if (i == 2) {
                a = 10;
            }
            $("#choose input").attr("checked",false);
            getmap(a);
            driving(i);
        });
    });
    $("#transit_div ul li ").each(function () {
        $(this).click(function () {
            var i = $(this).index();
            $(this).addClass("action_o").siblings("li").removeClass("action_o");
            $("#r-result").html("");
            map.clearOverlays();
            transit(i);
        });
    });
    var routePolicy_transit = [BMAP_TRANSIT_POLICY_LEAST_TIME, BMAP_TRANSIT_POLICY_LEAST_TRANSFER, BMAP_TRANSIT_POLICY_AVOID_SUBWAYS];
    var routePolicy_driving = [BMAP_DRIVING_POLICY_LEAST_TIME, BMAP_DRIVING_POLICY_LEAST_DISTANCE, BMAP_DRIVING_POLICY_AVOID_HIGHWAYS];
    $("#transfer_but").click(function () {
        transit();
    });
    $("#driving_but").click(function () {
        driving();
        getmap();
        $("#driving_div ul li:eq(0)").addClass("action_o").siblings("li").removeClass("action_o");
        $("#choose input").attr("checked",false);
    });
    $("#walking_but").click(function () {
        walking();
    });
    //公交规划
    function transit(i) {
        var transit = new BMap.TransitRoute(map, {
            renderOptions: {
                map: map,
                panel: "r-result"
            },
            policy: 0
        });
        map.clearOverlays();
        var i = i ? i : 0;
        var start = $("#start").val();
        var end = $("#end").val();
        var route = routePolicy_transit[i];
        transit.setPolicy(route);
        transit.search(start, end);
    }
    ;
    //驾车规划
    function driving(i) {
        map.clearOverlays();
        var i = i ? i : 0;
        var start = $("#start").val();
        var end = $("#end").val();
        var route = routePolicy_driving[i];
        var driving = new BMap.DrivingRoute(map, {
            renderOptions: {
                map: map,
                autoViewport: true,
                panel: "r-result"
            },
            policy: route
        });
        driving.search(start, end);
//        getPath(start, end)
    }
    ;
    //获取path，地图展示添加图层
    function getmap(c) {
        var a = $("#start").val();
        var b = $("#end").val();
        var c = c ? c : 13;
        console.log(a);
        console.log(b);
        console.log(c);
        if (a != "" && b != "") {
            $.ajax({
                type: 'post',
                url: allUrl,
                async: false,
                cache: false,
                data: {
                    type: "trip_planning_layer_cover",
                    ORIGIN: a,
                    DESTINATION: b,
                    TACTICS: c,
                },
                jsonp: "callbackparam",
                //服务端用于接收callback调用的function名的参数
                jsonpCallback: "data",
                dataType: 'jsonp',
                beforeSend: function () {

                },
                success: function (data) {
                    //选择显示哪个叠加层
                    updateInfo();
                    if (data) {
                        $("#choose").show();
                        var FUWUQU = data.FUWUQU;
                        var LVYOU = data.LVYOU;
                        var SHOUFEIZHAN = data.SHOUFEIZHAN;
                        //选择显示哪个叠加层
                        $("#choose input").each(function (i) {
                            if (i == 0) {
                                $(this).attr('data-SHOUFEIZHAN', SHOUFEIZHAN)
                            }
                            if (i == 1) {
                                $(this).attr('data-FUWUQU', FUWUQU)
                            }
                            if (i == 2) {
                                $(this).attr('data-LVYOU', LVYOU)
                            }

                        })
                    }
                    else {
                        $("#choose").hide();
                    }
                }
            });
        }

    }
    //更新图层数据;
    function updateInfo(){
        $("#choose input").each(function (i) {
            if (i == 0) {
                if($(this).attr('data-SHOUFEIZHAN')){
                    $(this).removeAttr('data-SHOUFEIZHAN')
                }
                $(this).attr('data-SHOUFEIZHAN', SHOUFEIZHAN)
            }
            if (i == 1) {
                if($(this).attr('data-FUWUQU')){
                    $(this).removeAttr('data-FUWUQU')
                }
                $(this).attr('data-FUWUQU', FUWUQU)
            }
            if (i == 2) {
                if($(this).attr('data-LVYOU')){
                    $(this).removeAttr('data-LVYOU')
                }
                $(this).attr('data-LVYOU', LVYOU)
            }

        })
    }
    //选择添加哪个图层；
    $("#choose input").each(function (i) {
        $(this).click(function () {
            if (i == 0) {
                if (this.checked == true) {
                    var data = $(this).attr('data-SHOUFEIZHAN');
                    data = eval(data);
                    console.log(data);
                    if (data.length != 0) {
                        var opts = {
                            width: 120,     // 信息窗口宽度
                            title: "收费站信息", // 信息窗口标题
                        }
                        for (var s = 0; s < data.length; s++) {
                            var positionX = data[s].coordinateX;
                            var positionY = data[s].coordinateY;
                            data[s].openStatus = data[s].openStatus == 0 ? "关闭" : "正常运行";
                            data[s].position = data[s].position ? data[s].position : "暂无数据";
                            data[s].destination = data[s].destination ? data[s].destination : "暂无数据";
                            var point1 = new BMap.Point(positionX, positionY);
                            //创建图标
                            var taxiIcon = new BMap.Icon("../../images/shoufeizhan.png", new BMap.Size(24, 24));
                            var marker1 = new BMap.Marker(point1, {
                                icon: taxiIcon
                            });// 创建标注
                            map.addOverlay(marker1);
                            var content = "<p>名称:  " + data[s].stationName + "</p>"+
                                    "<p>服务状态:  " + data[s].openStatus + "</p>" +
                                    "<p>线路:  " + data[s].position + "</p>" +
                                    "<p>通往:  " + data[s].destination + "" + data[s].travel + "</p>"
                            addClickHandler(content, marker1);
                            function addClickHandler(content, marker) {
                                marker.addEventListener("onmouseover", function (e) {
                                    openInfo(content, e)
                                })
                            }
                            function openInfo(content, e) {
                                var p = e.target;
                                var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
                                var infoWindow = new BMap.InfoWindow(content, opts);  // 创建信息窗口对象
                                map.openInfoWindow(infoWindow, point); //开启信息窗口
                            }
                        }

                    }
                } else {
                    map.clearOverlays();
                    getIndex();
                    getElse();
                }
            }
            if (i == 1) {
                if (this.checked == true) {
                    var data = $(this).attr('data-FUWUQU')
                    data = eval(data);
                    console.log(data);
                    if (data.length != 0) {
                        var opts = {
                            width: 120,     // 信息窗口宽度
                            title: "服务区信息", // 信息窗口标题
                        }
                        for (var s = 0; s < data.length; s++) {
                            var positionX = data[s].coordinateX;
                            var positionY = data[s].coordinateY;
                            data[s].openStatus = data[s].openStatus == 0 ? "关闭" : "正常运行";
                            data[s].position = data[s].position ? data[s].position : "暂无数据";
                            data[s].destination = data[s].destination ? data[s].destination : "暂无数据";
                            var point1 = new BMap.Point(positionX, positionY);
                            //创建图标
                            var taxiIcon = new BMap.Icon("../../images/fuwuqu.png", new BMap.Size(24,24));
                            var marker1 = new BMap.Marker(point1, {
                                icon: taxiIcon
                            });// 创建标注
                            map.addOverlay(marker1);
                            var content = "<p>名称:  "+data[s].serviceName+"</p>"+
                                    "<p>服务状态:  " + data[s].openStatus + "</p>" +
                                    "<p>线路:  " + data[s].position + "</p>" +
                                    "<p>通往:  " + data[s].destination + "</p>"
                            addClickHandler(content, marker1);
                            function addClickHandler(content, marker) {
                                marker.addEventListener("onmouseover", function (e) {
                                    openInfo(content, e)
                                })
                            }
                            function openInfo(content, e) {
                                var p = e.target;
                                var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
                                var infoWindow = new BMap.InfoWindow(content, opts);  // 创建信息窗口对象
                                map.openInfoWindow(infoWindow, point); //开启信息窗口
                            }
                        }
                    }
                } else {
                    map.clearOverlays();
                    getIndex();
                    getElse();
                }

            }
            if (i == 2) {
                if (this.checked == true) {
                    var data = $(this).attr('data-LVYOU');
                    data = eval(data);
                    console.log(data);
                    if (data.length != 0) {
                        var opts = {
                            width: 120,     // 信息窗口宽度
                            title: "景点信息", // 信息窗口标题
                        }
                        for (var s = 0; s < data.length; s++) {
                            var zb = data[s].ZB;
                            zb=  zb.split(",");
                            var a =  zb.slice(0,1);
                            var b = zb.slice(1,2);
                            var dz = data[s].DZ;
                            var jqmc = data[s].JQMC;
                            var point1 = new BMap.Point(a,b);
                            //创建图标
                            var taxiIcon = new BMap.Icon("../../images/lvyou.png", new BMap.Size(24, 24));
                            var marker1 = new BMap.Marker(point1, {
                                icon: taxiIcon
                            });// 创建标注
                            map.addOverlay(marker1);
                            var content = "<p>景区名称:  " + jqmc + "</p><br/>" +
                                    "<p>地址:  " + dz + "</p>";
                            addClickHandler(content, marker1);
                            function addClickHandler(content, marker) {
                                marker.addEventListener("onmouseover", function (e) {
                                    openInfo(content, e)
                                })
                            }
                            function openInfo(content, e) {
                                var p = e.target;
                                var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
                                var infoWindow = new BMap.InfoWindow(content, opts);  // 创建信息窗口对象
                                map.openInfoWindow(infoWindow, point); //开启信息窗口
                            }
//
                        }

                    }
                } else {
                    map.clearOverlays();
                    getIndex();
                    getElse();
                }

            }
        });
    })
    //获取出行方式再次执行；
    function getIndex(){
        $("#driving_div li").each(function (i) {
            if($(this).hasClass("action_o")){
                driving(i);
            }
        });
    }
    //再次获取选中的多选按钮的信息；
    function getElse(){
        $("#choose input").each(function (i) {
//            if (this.checked == true) {
                if (i == 0) {
                    if (this.checked == true) {
                        var data = $(this).attr('data-SHOUFEIZHAN');
                        data = eval(data);
                        if (data.length != 0) {
                            var opts = {
                                width: 120,     // 信息窗口宽度
                                title: "收费站信息", // 信息窗口标题
                            }
                            for (var s = 0; s < data.length; s++) {
                                var positionX = data[s].coordinateX;
                                var positionY = data[s].coordinateY;
                                data[s].openStatus = data[s].openStatus == 0 ? "关闭" : "正常运行";
                                data[s].position = data[s].position ? data[s].position : "暂无数据";
                                data[s].destination = data[s].destination ? data[s].destination : "暂无数据";
                                var point1 = new BMap.Point(positionX, positionY);
                                //创建图标
                                var taxiIcon = new BMap.Icon("../../images/shoufeizhan.png", new BMap.Size(24, 24));
                                var marker1 = new BMap.Marker(point1, {
                                    icon: taxiIcon
                                });// 创建标注
                                map.addOverlay(marker1);
                                var content = "<p>名称:  " + data[s].stationName + "</p>" +
                                        "<p>服务状态:  " + data[s].openStatus + "</p>" +
                                        "<p>线路:  " + data[s].position + "</p>" +
                                        "<p>通往:  " + data[s].destination + "" + data[s].travel + "</p>"
                                addClickHandler(content, marker1);
                                function addClickHandler(content, marker) {
                                    marker.addEventListener("onmouseover", function (e) {
                                        openInfo(content, e)
                                    })
                                }
                                function openInfo(content, e) {
                                    var p = e.target;
                                    var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
                                    var infoWindow = new BMap.InfoWindow(content, opts);  // 创建信息窗口对象
                                    map.openInfoWindow(infoWindow, point); //开启信息窗口
                                }
                            }

                        }
                    } else {
                        map.clearOverlays();
                        getIndex()
                    }
                }
                if (i == 1) {
                    if (this.checked == true) {
                        var data = $(this).attr('data-FUWUQU')
                        data = eval(data);
                        if (data.length != 0) {
                            var opts = {
                                width: 120,     // 信息窗口宽度
                                title: "服务区信息", // 信息窗口标题
                            }
                            for (var s = 0; s < data.length; s++) {
                                var positionX = data[s].coordinateX;
                                var positionY = data[s].coordinateY;
                                data[s].openStatus = data[s].openStatus == 0 ? "关闭" : "正常运行";
                                data[s].position = data[s].position ? data[s].position : "暂无数据";
                                data[s].destination = data[s].destination ? data[s].destination : "暂无数据";
                                var point1 = new BMap.Point(positionX, positionY);
                                //创建图标
                                var taxiIcon = new BMap.Icon("../../images/fuwuqu.png", new BMap.Size(24,24));
                                var marker1 = new BMap.Marker(point1, {
                                    icon: taxiIcon
                                });// 创建标注
                                map.addOverlay(marker1);
                                var content = "<p>名称:  "+data[s].serviceName+"</p>"+
                                        "<p>服务状态:  " + data[s].openStatus + "</p>" +
                                        "<p>线路:  " + data[s].position + "</p>" +
                                        "<p>通往:  " + data[s].destination + "</p>"
                                addClickHandler(content, marker1);
                                function addClickHandler(content, marker) {
                                    marker.addEventListener("onmouseover", function (e) {
                                        openInfo(content, e)
                                    })
                                }
                                function openInfo(content, e) {
                                    var p = e.target;
                                    var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
                                    var infoWindow = new BMap.InfoWindow(content, opts);  // 创建信息窗口对象
                                    map.openInfoWindow(infoWindow, point); //开启信息窗口
                                }
                            }
                        }
                    } else {
                        map.clearOverlays();
                        getIndex()
                    }

                }
                if (i == 2) {
                    if (this.checked == true) {
                        var data = $(this).attr('data-LVYOU');
                        data = eval(data);
                        if (data.length != 0) {
                            var opts = {
                                width: 120,     // 信息窗口宽度
                                title: "景点信息", // 信息窗口标题
                            }
                            for (var s = 0; s < data.length; s++) {
                                var zb = data[s].ZB;
                                zb=  zb.split(",");
                                var a =  zb.slice(0,1);
                                var b = zb.slice(1,2);
                                var dz = data[s].DZ;
                                var jqmc = data[s].JQMC;
                                var point1 = new BMap.Point(a,b);
                                //创建图标
                                var taxiIcon = new BMap.Icon("../../images/lvyou.png", new BMap.Size(24, 24));
                                var marker1 = new BMap.Marker(point1, {
                                    icon: taxiIcon
                                });// 创建标注
                                map.addOverlay(marker1);
                                var content = "<p>景区名称:  " + jqmc + "</p><br/>" +
                                        "<p>地址:  " + dz + "</p>";
                                addClickHandler(content, marker1);
                                function addClickHandler(content, marker) {
                                    marker.addEventListener("onmouseover", function (e) {
                                        openInfo(content, e)
                                    })
                                }
                                function openInfo(content, e) {
                                    var p = e.target;
                                    var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
                                    var infoWindow = new BMap.InfoWindow(content, opts);  // 创建信息窗口对象
                                    map.openInfoWindow(infoWindow, point); //开启信息窗口
                                }
//
                            }

                        }
                    } else {
                        map.clearOverlays();
                        getIndex()
                    }

                }
//            }
        })
    }
    //步行规划
    function walking() {
        map.clearOverlays();
        var start = $("#start").val();
        var end = $("#end").val();
        var walking = new BMap.WalkingRoute(map, {
            renderOptions: {
                map: map,
                autoViewport: true,
                panel: "r-result"
            }
        });
        walking.search(start, end);

    }
    ;

    //目的地跳转过来赋值
    if (window.sessionStorage.getItem("mudidi")) {
        $("#end").val(window.sessionStorage.getItem("mudidi"));
        window.sessionStorage.removeItem("mudidi");
        var ac = new BMap.Autocomplete(    //建立一个自动完成的对象
                {
                    "input": "start",
                    "location": map,
                }
        );
        fn(ac);
        $("#end").keyup(function () {
            if ($(this).val() == "") {
                var bc = new BMap.Autocomplete(    //建立一个自动完成的对象
                        {
                            "input": "end",
                            "location": map,
                        }
                );
                fn(bc);
            }
        })

    } //出行跳转过来赋值
    else if (window.sessionStorage.getItem("chuxingInfo")) {
        var obj2 = JSON.parse(window.sessionStorage.getItem("chuxingInfo"));
        $("#start").val(obj2.start);
        $("#end").val(obj2.end);
        window.sessionStorage.removeItem("chuxingInfo");
        driving();
        $("#start").keyup(function () {
            if ($(this).val() == "") {
                var ac = new BMap.Autocomplete(    //建立一个自动完成的对象
                        {
                            "input": "start",
                            "location": map,
                        }
                );
                fn(ac);
            }
        })
        $("#end").keyup(function () {
            if ($(this).val() == "") {
                var bc = new BMap.Autocomplete(    //建立一个自动完成的对象
                        {
                            "input": "end",
                            "location": map,
                        }
                );
                fn(bc);
            }
        })
    }
    else {
        var ac = new BMap.Autocomplete(    //建立一个自动完成的对象
                {
                    "input": "start",
                    "location": map,
                }
        );
        var bc = new BMap.Autocomplete(    //建立一个自动完成的对象
                {
                    "input": "end",
                    "location": map,
                }
        );
        fn(ac);
        fn(bc);
    }

    // 百度地图API功能
    function G(id) {
        return document.getElementById(id);
    }
    function fn(ac) {
        ac.addEventListener("onhighlight", function (e) {  //鼠标放在下拉列表上的事件
            var str = "";
            var _value = e.fromitem.value;
            var value = "";
            if (e.fromitem.index > -1) {
                value = _value.province + _value.city + _value.district + _value.street + _value.business;
            }
            str = "FromItem<br />index = " + e.fromitem.index + "<br />value = " + value;
            value = "";
            if (e.toitem.index > -1) {
                _value = e.toitem.value;
                value = _value.province + _value.city + _value.district + _value.street + _value.business;
            }
            str += "<br />ToItem<br />index = " + e.toitem.index + "<br />value = " + value;
            G("searchResultPanel").innerHTML = str;
        });
        var myValue;
        ac.addEventListener("onconfirm", function (e) {    //鼠标点击下拉列表后的事件
            var _value = e.item.value;
            myValue = _value.province + _value.city + _value.district + _value.street + _value.business;
            G("searchResultPanel").innerHTML = "onconfirm<br />index = " + e.item.index + "<br />myValue = " + myValue;
        });
    }
    //目的地收藏功能
    $("#end").keyup(function () {
        $("#DEST_collect").css({'background-image': 'url(../../images/Icon_sc_03.png)'})
    })
    $("#DEST_collect").click(function () {
        var pIfon = $("#tishiInfo");
        var endInfo = $("#end").val();
        //判断是否存在用户
        var that = $(this);
        if (window.sessionStorage.getItem("temp")) {
            var obj2 = JSON.parse(window.sessionStorage.getItem("temp"));
            obj2_true = obj2.LocalUsername;
            $.ajax({
                type: 'post',
                url: allUrl,
                async: false,
                cache: false,
                data: {
                    type: "end_collections",
                    USERNAME: obj2_true,
                    ENDSTATION: endInfo,
                },
                jsonp: "callbackparam",
                //服务端用于接收callback调用的function名的参数
                jsonpCallback: "data",
                dataType: 'jsonp',
                beforeSend: function () {
                    if (endInfo == "" || endInfo == undefined) {
                        pIfon.html("请输入目的地").show().fadeOut(2000);
                        return false;
                    }
                },
                success: function (data) {
                    if (data.MSG == "成功") {
                        that.css({'background-image': 'url(../../images/Icon_sc_06.png)'});
                        pIfon.html("收藏成功").show().fadeOut(2000);
                    } else if (data.MSG == "已存在") {
                        pIfon.html("目的地已收藏").show().fadeOut(2000);
                    } else if (data.MSG == "失败") {
                        pIfon.html("发生未知错误,请稍候再试").show().fadeOut(2000);
                    }
                }
            });
        } else {
            pIfon.html("请先登录").show().fadeOut(2000);
        }
    });

</script>
</body>
</html>